<?php

namespace common\models\user;

use common\models\spoker\Spoker;
use Yii;

/**
 * This is the model class for table "user".
 * @property Spoker $spoker
 *
 * @property int $id
 * @property string $wx_mini_openid 微信小程序openid
 * @property string $avatar_url 微信头像url
 * @property string $nickname 昵称
 * @property string $mobile 手机号【微信授权】
 * @property int $spoker_id 代言人ID
 * @property int $withdraw_id 提现账号ID
 * @property int $status 状态【-1：删除、0：禁用、1：启用】
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class User extends \common\models\base\BaseModel
{
    const STATUS_DELETE = -1;// 删除
    const STATUS_INVALID = 0;// 失效
    const STATUS_ENABLE = 1;// 正常

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'user';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['spoker_id', 'withdraw_id', 'status', 'created_at', 'updated_at'], 'integer'],
            [['wx_mini_openid'], 'string', 'max' => 64],
            [['avatar_url'], 'string', 'max' => 256],
            [['nickname'], 'string', 'max' => 32],
            [['mobile'], 'string', 'max' => 16],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'wx_mini_openid' => '微信小程序openid',
            'avatar_url' => '微信头像url',
            'nickname' => '昵称',
            'mobile' => '手机号【微信授权】',
            'spoker_id' => '代言人ID',
            'withdraw_id' => '提现账号ID',
            'status' => '状态【-1：删除、0：禁用、1：启用】',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }


    /**
     * 关联小程序用户代言人
     */
    public function getSpoker()
    {
        return $this->hasOne(Spoker::class, ['id' => 'spoker_id']);
    }
}
